package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.zy.openchat.core.model.audio.AudioInfo;
import com.zy.openchat.core.model.voice.VoiceInfo;
import com.zy.openchat.core.model.file.DocumentInfo;
import com.zy.openchat.core.model.location.MsgLocationInfo;
import com.zy.openchat.core.model.photo.PhotoInfo;
import com.zy.openchat.core.model.user.MobileContactInfo;
import com.zy.openchat.core.model.video.VideoInfo;

import java.util.ArrayList;
import java.util.List;

public class MessageContent implements Parcelable {
    //maybe @messageText @messagePhoto ...
    @SerializedName("@type")
    public String type;

    //群成员被移除对应的userid
    public long user_id;
    //被邀请进群组
    public List<Long> member_user_ids;

    public long message_id;

    //1、会话标题变化消息
    //2、文件消息标题
    public String title;

    //图片相关
    public PhotoInfo photo;
    //视频相关
    public VideoInfo video;
    //语音相关
    public AudioInfo audio;

    //PC语音相关
    public VoiceInfo voice_note;

    //文件相关
    public DocumentInfo document;
    //位置相关
    public MsgLocationInfo location;

    public VideoInfo animation;

    public TextInfo text;

    public MobileContactInfo contact;

    public FormatTextInfo caption;


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.type);
        dest.writeLong(this.user_id);
        dest.writeList(this.member_user_ids);
        dest.writeLong(this.message_id);
        dest.writeString(this.title);
        dest.writeParcelable(this.photo, flags);
        dest.writeParcelable(this.video, flags);
        dest.writeParcelable(this.audio, flags);
        dest.writeParcelable(this.voice_note, flags);
        dest.writeParcelable(this.document, flags);
        dest.writeParcelable(this.location, flags);
        dest.writeParcelable(this.animation, flags);
        dest.writeParcelable(this.text, flags);
        dest.writeParcelable(this.contact, flags);
        dest.writeParcelable(this.caption, flags);
    }

    public void readFromParcel(Parcel source) {
        this.type = source.readString();
        this.user_id = source.readLong();
        this.member_user_ids = new ArrayList<Long>();
        source.readList(this.member_user_ids, Long.class.getClassLoader());
        this.message_id = source.readLong();
        this.title = source.readString();
        this.photo = source.readParcelable(PhotoInfo.class.getClassLoader());
        this.video = source.readParcelable(VideoInfo.class.getClassLoader());
        this.audio = source.readParcelable(AudioInfo.class.getClassLoader());
        this.voice_note = source.readParcelable(VoiceInfo.class.getClassLoader());
        this.document = source.readParcelable(DocumentInfo.class.getClassLoader());
        this.location = source.readParcelable(MsgLocationInfo.class.getClassLoader());
        this.animation = source.readParcelable(VideoInfo.class.getClassLoader());
        this.text = source.readParcelable(TextInfo.class.getClassLoader());
        this.contact = source.readParcelable(MobileContactInfo.class.getClassLoader());
        this.caption = source.readParcelable(FormatTextInfo.class.getClassLoader());
    }

    public MessageContent() {
    }

    protected MessageContent(Parcel in) {
        this.type = in.readString();
        this.user_id = in.readLong();
        this.member_user_ids = new ArrayList<Long>();
        in.readList(this.member_user_ids, Long.class.getClassLoader());
        this.message_id = in.readLong();
        this.title = in.readString();
        this.photo = in.readParcelable(PhotoInfo.class.getClassLoader());
        this.video = in.readParcelable(VideoInfo.class.getClassLoader());
        this.audio = in.readParcelable(AudioInfo.class.getClassLoader());
        this.voice_note = in.readParcelable(VoiceInfo.class.getClassLoader());
        this.document = in.readParcelable(DocumentInfo.class.getClassLoader());
        this.location = in.readParcelable(MsgLocationInfo.class.getClassLoader());
        this.animation = in.readParcelable(VideoInfo.class.getClassLoader());
        this.text = in.readParcelable(TextInfo.class.getClassLoader());
        this.contact = in.readParcelable(MobileContactInfo.class.getClassLoader());
        this.caption = in.readParcelable(FormatTextInfo.class.getClassLoader());
    }

    public static final Creator<MessageContent> CREATOR = new Creator<MessageContent>() {
        @Override
        public MessageContent createFromParcel(Parcel source) {
            return new MessageContent(source);
        }

        @Override
        public MessageContent[] newArray(int size) {
            return new MessageContent[size];
        }
    };
}
